package com.huawei.esdk.tp.device.smc.convert;

import com.huawei.esdk.platform.common.SDKResult;
import com.huawei.esdk.platform.common.config.ConfigManager;
import com.huawei.esdk.platform.common.utils.StringUtils;
import com.huawei.esdk.tp.cxf.enumgen.DialMode;
import com.huawei.esdk.tp.cxf.enumgen.SiteType;
import com.huawei.esdk.tp.domain.model.Site;
import com.huawei.esdk.tp.domain.model.bean.ContinuousPresenceCapability;
import com.huawei.esdk.tp.southcommu.cxf.gen.AddSiteInScheduledConfSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.ConferenceIdSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.GetContinuousPresenceInfoResponseSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.ScheduleSiteParam2South;

/** * @author w00208247 * *  */
public class TPConfCtrConvert
{
    /**
     * 添加会场到会议，根据参数得到南向soap bean 用于向SMC产品发消息的情况 response model2soap
     */
    public AddSiteInScheduledConfSouth addSiteToConf2soap(String confId, Site site)
    {
        //领域bean转南向soapBean
        AddSiteInScheduledConfSouth addSiteToConf = new AddSiteInScheduledConfSouth();
        
        ConferenceIdSouth conferenceId = new ConferenceIdSouth();
        conferenceId.setConfInternalId(Long.parseLong(confId));
        addSiteToConf.setConfId(conferenceId);
        
        ScheduleSiteParam2South scheduleSiteParam2 = new ScheduleSiteParam2South();
        scheduleSiteParam2.setName(site.getName());
        scheduleSiteParam2.setUri(site.getUri());
        
        scheduleSiteParam2.setDialingMode(DialMode.valueOf(site.getDialingMode()));
        scheduleSiteParam2.setType(SiteType.valueOf(site.getSiteType()));
        
        addSiteToConf.setSiteParam(scheduleSiteParam2);
        
        return addSiteToConf;
    }
    
    public SDKResult<ContinuousPresenceCapability> getContinuousPresenceInfoCommSoap2model(
        GetContinuousPresenceInfoResponseSouth res)
    {
        SDKResult<ContinuousPresenceCapability> result = new SDKResult<ContinuousPresenceCapability>();
        result.setErrCode(res.getGetContinuousPresenceInfoResult().getErrCode());
        if (0 != result.getErrCode())
        {
            return result;
        }
        result.setSubSystem(String.valueOf(res.getGetContinuousPresenceInfoResult().getSubSystem()));
        result.setDescription(res.getGetContinuousPresenceInfoResult().getDescription());
        
        ContinuousPresenceCapability southInfo = new ContinuousPresenceCapability();
        southInfo.setCpResource(res.getCpResource());
        southInfo.setTargets(res.getTargets().getString());
        southInfo.setSupportCPModes(res.getSupportCPModes().getContinuousPresenceMode());
        
        result.setResult(southInfo);
        
        return result;
    }
    
    
     /** 
     * 设置多画面参数转换
     * 2015.1.14，废弃boolean targetIsSiteUri参数，不需要判断会场是否存在
     * @param target
     * @return
     * @see [类、类#方法、类#成员]
     */
    public String continuousPresenceTargetMappingConvert(String target)
    {
        if (StringUtils.isEmpty(target))
        {
            // 空值转成(%CP)
            target = ConfigManager.getInstance().getValue("professional.setContinuousPresence.target_(%CP)");
        }
        else if (target.startsWith(ConfigManager.getInstance().getValue("professional.setContinuousPresence.target_("))
            && target.endsWith(ConfigManager.getInstance().getValue("professional.setContinuousPresence.target_)")))
        {
            // 需要将(xxxxx)转换成xxxxx(%CP)
            target =
                target.replaceAll("\\"
                    + ConfigManager.getInstance().getValue("professional.setContinuousPresence.target_("),
                    "");
            target =
                target.replaceAll("\\"
                    + ConfigManager.getInstance().getValue("professional.setContinuousPresence.target_)"),
                    "");
            
            target = target + ConfigManager.getInstance().getValue("professional.setContinuousPresence.target_(%CP)");
        }
        else
        {
            // 将x转换成(%CPx)
            target =
                ConfigManager.getInstance().getValue("professional.setContinuousPresence.target_(%CP") + target
                    + ConfigManager.getInstance().getValue("professional.setContinuousPresence.target_)");
        }
        
        return target;
    }
}
